using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Web;
using System.Windows.Forms;

namespace ThunderCode
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private string thunder = "thunder://";
        private string flashget = "flashget://";
        private string thunderhead = "AA";
        private string thundertail = "ZZ";

        private void button1_Click(object sender, EventArgs e)
        {
            string fromUrl = HttpUtility.UrlEncode(textBox1.Text);
            string toUrl = Base64.EncodingString(thunderhead + fromUrl + thundertail);
            textBox2.Text = thunder + toUrl;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            string fromUrl;
            if (textBox1.Text.StartsWith(thunder))
            {
                string aa = textBox1.Text.Substring(thunder.Length);
                fromUrl = Base64.DecodingString(textBox1.Text.Substring(thunder.Length));
            }
            else
                fromUrl = Base64.DecodingString(textBox1.Text);
            string toUrl = HttpUtility.UrlDecode(fromUrl);
            if (toUrl.StartsWith(thunderhead))
                toUrl = toUrl.Substring(thunderhead.Length);
            if (toUrl.EndsWith(thundertail))
                toUrl = toUrl.Substring(0, toUrl.Length - thundertail.Length);
            textBox2.Text = toUrl;
        }
    }
}